﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows;
// using CPlatePrintSys.Infrastructure.Helpers;
using CPlatePrintSys.Win.ViewModels;
using CPlatePrintSys.Win.Views;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Navigation.Regions;
using Prism.Unity;
using Prism.Dialogs;
using Prism.Events;
using CPlatePrintSys.Application.Services;
using CPlatePrintSys.Domain.Services;

namespace CPlatePrintSys.Win
{
    /// <summary>  
    /// App.xaml 的交互逻辑  
    /// </summary>  
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            // Use the IContainerProvider to resolve MainWindow
            return Container.Resolve<Shell>();
        }

        protected override void OnInitialized()
        {
            base.OnInitialized();
            // AMLog.Info("------ main window inited. ------");
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new XamlModuleCatalog(new Uri("/CPlatePrintSys.Win;component/ModuleCatalog.xaml", UriKind.Relative));
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            // 注册所有视图
            containerRegistry.RegisterForNavigation<LoginWindowView>();
            containerRegistry.RegisterForNavigation<MainWindow>();
            containerRegistry.RegisterForNavigation<HomeView>();
            containerRegistry.RegisterForNavigation<ProcessSequenceView>();
            containerRegistry.RegisterForNavigation<MaterialManageView>();
            containerRegistry.RegisterForNavigation<SettingsView>();
            containerRegistry.RegisterForNavigation<ShipNoConfigView>();
            containerRegistry.RegisterForNavigation<AboutView>();

            containerRegistry.RegisterForNavigation<ShipNoConfigView, ShipNoConfigViewModel>();

            // 注册服务
            containerRegistry.RegisterSingleton<ShipInfoService>();
            containerRegistry.RegisterSingleton<AmService>();
            containerRegistry.RegisterSingleton<CadWinService>();
            containerRegistry.RegisterSingleton<KmacsService>();
            containerRegistry.RegisterSingleton<GlobalConfigService>();
            containerRegistry.RegisterSingleton<UserService>();
            containerRegistry.RegisterSingleton<LayoutService>();
            
            // 注册工作空间服务（仅本地存储）
            containerRegistry.RegisterSingleton<IWorkSpaceService, WorkSpaceService>();

            // 注册接口
            containerRegistry.RegisterSingleton<ILayoutService, LayoutService>();
            containerRegistry.RegisterSingleton<IUserService, UserService>();
            containerRegistry.RegisterSingleton<IGlobalConfigService, GlobalConfigService>();


            // 注册全局配置视图
            containerRegistry.RegisterForNavigation<RoundingRuleConfigView, RoundingRuleConfigViewModel>();
            containerRegistry.RegisterForNavigation<LayerColorConfigView, LayerColorConfigViewModel>();
            containerRegistry.RegisterForNavigation<OutputDirectoryConfigView, OutputDirectoryConfigViewModel>();
            containerRegistry.RegisterForNavigation<InterfaceConfigView, InterfaceConfigTabbedViewModel>();

        }
    }
}
